/*
 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package org.javaongems.client.rt.awt;

/**
 * This code was clipped from the Sun JDK. The following classes are very common
 * to any math or UI library. Given that Java developers already know these
 * classes, i didnt want to re-implement them with different contracts. Can 
 * someone advise what to do. Until then I will use these copies.
 * <ul>
 * 	<li> Dimension
 * 	<li> Point
 *  <li> Rectangle
 * </ul>
 */
public class Dimension {
	public int width, height;

	public Dimension() {
		this(0, 0);
	}

	public Dimension(Dimension d) {
		this(d.width, d.height);
	}

	public Dimension(int width, int height) {
		this.width = width;
		this.height = height;
	}

	public double getWidth() {
		return width;
	}

	public double getHeight() {
		return height;
	}

	public void setSize(double width, double height) {
		this.width = (int) Math.ceil(width);
		this.height = (int) Math.ceil(height);
	}

	public Dimension getSize() {
		return new Dimension(width, height);
	}

	public void setSize(Dimension d) {
		setSize(d.width, d.height);
	}

	public void setSize(int width, int height) {
		this.width = width;
		this.height = height;
	}

	public boolean equals(Object obj) {
		if (obj instanceof Dimension) {
			Dimension d = (Dimension) obj;
			return (width == d.width) && (height == d.height);
		}
		return false;
	}

	public int hashCode() {
		int sum = width + height;
		return sum * (sum + 1) / 2 + width;
	}

	public String toString() {
		return "Dim[width=" + width + ",height=" + height
				+ "]";
	}

}
